/**
 * 递归大目录，删除匹配的文件
 */
const fs = require('fs')
const path = require('path')
deleteFile('D://重命名文件夹')
// 获得目录
let reg =/(毕业证|劳动合同)/
function deleteFile(path,fname){
   fs.readdir(path,(err,files)=>{
    files.forEach(item=>{
        let pathName = path+'/'+item
        let stat = fs.lstatSync(pathName)
          // 判断是否是文件夹
        if(stat.isDirectory()){
            // 递归删除
            deleteFile(`${path}/${item}`,item)
            return
        }
        // 判断是否满足关键字
        if(reg.test(item)){
            fs.writeFileSync('./删除的文件.txt',`\r\n${pathName}`,{flag:'a'})
            fs.rmSync(pathName)
            return
        }
       
    })
   })
}
